#include <string.h>
#include "driver/gpio.h"
#include "timer_task.h"

typedef enum base_handle_type
{
    BASE_HANDLE_REBOOT, /* 复位 */
    BASE_HANDLE_MAX,    /* 最大值 */
} base_handle_type_t;

static const timer_action_handle_item_t action_handles[BASE_HANDLE_MAX] = {
    {
        .name = "reboot",
        .desc = "reboot system",
        .i18n = "重启系统",
        .desc_i18n = "传任何值都会重启系统",
    },
};

static const timer_action_param_item_t action_params[] = {
    {
        .name = "close",
        .i18n = "关闭",
        .value = 0,
        .handles = 0xFF,
    },
    {
        .name = "open",
        .i18n = "打开",
        .value = 0,
        .handles = 0xFF,
    },
};

static uint8_t timer_action_cb(uint8_t handle, uint8_t param)
{
    if ((uint8_t)handle >= BASE_HANDLE_MAX || (uint8_t)param > 1)
        return ACTION_RESULT_FAIL;
    switch ((uint8_t)handle)
    {
    case BASE_HANDLE_REBOOT:
    {
        extern void call_reboot(void);
        call_reboot();
        break;
    }
    default:
        return ACTION_RESULT_FAIL;
    }
    return ACTION_RESULT_SUCCESS;
}

// static uint8_t timer_action_create_task(void *timer_action, uint8_t handle, uint8_t param)
// {
//     if (!timer_action || (uint8_t)handle >= BASE_HANDLE_MAX || (uint8_t)param > 1)
//         return 0;
//     timer_action_t *item = timer_action;
//     if (handle == BASE_HANDLE_REBOOT)
//         strncpy(item->name, "重启系统", sizeof(item->name));
//     // else
//     //     strncpy(item->name, dvc_param_handle_to_str[handle][param], sizeof(item->name));
//     item->handle = handle;
//     item->param = param;
//     item->cb = timer_action_cb;
//     return 1;
// }

ADD_TIMER_ACTION(BASE, timer_action_cb, action_handles, action_params)
